<template>
  <!-- <div class="home">
    <img alt="Vue logo" src="../assets/logo.png">
    <HelloWorld msg="Welcome to Your Vue.js App"/>
  </div> -->
  <div>
    <div class="flex-1">{{ $t("home") }}</div>
    <div style="height: 500px; width: 100%" id="chart"></div>
  </div>
</template>

<script>
// @ is an alias to /src
// import HelloWorld from '@/components/HelloWorld.vue'
import * as echarts from "echarts";

import { test } from "@/utils/api";
export default {
  name: "HomeView",
  data() {
    return {
      v1: "aaaaaaaaaa",
      windowH: window.innerWidth,
    };
  },
  components: {
    // HelloWorld
  },
  methods: {
    testApi() {
      test().then((res) => {
        this.v1 = res;
        this.drawChat();
      });
    },
    drawChat() {
      var chartDom = document.getElementById("chart");
      if (myChart != null && myChart != "" && myChart != undefined) {
        // 3. 已存在则调用 dispose() 方法销毁
        myChart.dispose();
      }
      var myChart = echarts.init(chartDom);
      var option;
      option = {
        tooltip: {
          trigger: "axis",
        },
        xAxis: {
          type: "category",
          // data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
        },
        yAxis: {
          type: "value",
        },
        dataZoom: [
          {
            startValue: this.v1.length - 50,
          },
          {
            type: "inside",
          },
        ],
        visualMap: {
          top: 50,
          right: 10,
          pieces: [
            {
              gt: 0,
              lte: 20,
              color: "#93CE07",
            },
            {
              gt: 20,
              lte: 40,
              color: "#FBDB0F",
            },
            {
              gt: 40,
              lte: 60,
              color: "#FC7D02",
            },
            {
              gt: 60,
              lte: 80,
              color: "#FD0100",
            },
            {
              gt: 80,
              lte: 100,
              color: "#AA069F",
            },
          ],
          outOfRange: {
            color: "#999",
          },
        },
        series: [
          {
            data: this.v1,
            type: "line",
          },
        ],
      };

      option && myChart.setOption(option);
      window.addEventListener("resize", () => {
        myChart.resize();
      });
    },
  },
  created() {
    this.testApi();
  },
  mounted() {
    // this.drawChat();
  },
};
</script>
